<template>
  <div class="feedback-page">
    <h2>反馈您的问题</h2>
    <el-form :model="feedbackForm" label-width="80px">
      <el-form-item label="反馈类型">
        <el-radio-group v-model="feedbackForm.status">
          <el-radio label="退货退款" value="4"></el-radio>
          <el-radio label="退换货" value="5"></el-radio>
          <el-radio label="仅退款" value="6"></el-radio>
          <el-radio label="售后" value="7"></el-radio>
          <el-radio label="其它" value="8"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="反馈内容">
        <el-input type="textarea" v-model="feedbackForm.content" placeholder="请输入详细反馈信息"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitFeedback">提交反馈</el-button>
        <el-button @click="goBack">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import router from '@/router';
import {useRoute} from "vue-router";
import orderApi from "@/api/OrderApi.js";

const route = useRoute()

const feedbackForm = ref({
  id:route.query.orderId,
  status: '7',
  content: ''
});

// 提交反馈
const submitFeedback = () => {
  if (!feedbackForm.value.content) {
    ElMessage.error('反馈内容不能为空');
    return;
  }
  orderApi.updateInfo(feedbackForm.value)
      .then(resp => {
        if (resp.code === 10000) {
          ElMessage.success("提交成功")
          goBack()
        } else {
          ElMessage.error("提交失败")
        }
      })
}

// 返回订单列表
const goBack = () => {
  router.push('/user/center/order');
}
</script>

<style scoped>
.feedback-page {
  margin: 20px auto;
  padding: 20px;
  max-width: 600px;
  background-color: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 10px;
}

h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 20px;
}

.el-form-item {
  margin-bottom: 20px;
}
</style>
